Skip to content

fix(gitlab): find merge requests opened from a fork - #40894

Merged
juliusmarminge merged 4 commits into
pingdotgg:mainfrom
Abhiram-745:fix/gitlab-fork-mr-source-project
Nov 22, 2026
Merged

juliusmarminge merged 4 commits into
pingdotgg:mainfrom
Abhiram-745:fix/gitlab-fork-mr-source-project

Conversation

@Abhiram-745

Copy link
Copy Markdown
Contributor

Problem

On GitLab, T3 Code never finds a merge request opened from a fork.

Repro on main:

  1. Clone a GitLab project so origin is the upstream (group/upstream), and add your fork as another remote (alice/upstream).
  2. Check out feature/x, push it to the fork, and open a merge request into the upstream project (from T3 Code or the GitLab UI).
  3. T3 Code shows no merge request for the branch in Git status or the PR action. Clicking Create MR again sends the create request, and GitLab rejects it with "Another open merge request already exists for this source branch".

GitLabCli.listMergeRequests runs glab mr list --source-branch <branch> --output json. glab prints GitLab's merge request list rows (client-go BasicMergeRequest), which name the source project only by source_project_id. There is no source_project object in that output, and the GitLab MR API docs list none. normalizeGitLabMergeRequestRecord reads raw.source_project, so a fork MR comes back with isCrossRepository: true but no headRepositoryNameWithOwner or headRepositoryOwnerLogin. matchesBranchHeadContext in GitManager.ts then rejects every cross-repository MR whose head has neither, so both the status lookup and the existing-MR check before create miss it. The existing tests pass only because their fixtures include a source_project field that glab doesn't print.

Change

  • When a listed or viewed MR is cross-repository and came without a source project path, GitLabCli looks the project up once with glab api projects/<source_project_id> and fills headRepositoryNameWithOwner and headRepositoryOwnerLogin from its path_with_namespace, using the existing owner rule.
  • Lookups are cached by project id for the whole call, across pages.
  • A failed lookup leaves the fields unset, as they are today, so the list never fails because of it.
  • Same-project MRs, and records that already carry source_project, cause no extra glab call and come out unchanged.

Scope

This is a focused fix for an obvious bug in the GitLab adapter, so I didn't open an issue. #29791 made GitLab read a full page so GitManager's owner matching could pick the branch's own MR out of fork MRs, but that matching needs the source project, which real glab output doesn't include. #23439 changed fork MR creation, not the lookup.

Verification

  • New test in GitLabSourceControlProvider.git.test.ts, "names a fork merge request's source project from real glab list output". It lists four MRs in the real glab shape: two forks from one project, one same-project MR, and a fork whose project lookup returns bad JSON. On main it fails with expected [ { provider: 'gitlab', …(11) }, …(3) ] to match object [ { number: 1, …(3) }, …(3) ]. With the fix it passes, and it asserts the only glab api calls are projects/101 and projects/102: one per project, none for the same-project MR.
  • packages/source-control-gitlab passes (296 tests). apps/server GitManager.test.ts passes (160 tests).
  • vp fmt, vp lint and knip:check on the changed files are clean, and the package typecheck passes.
  • Not checked: a live GitLab instance. The output shape comes from glab's mr list JSON (client-go BasicMergeRequest) and the GitLab merge request API docs.

Code written with Claude Code (Claude Opus 5.5).

@github-actions github-actions Bot added vouch:unvouched Author is not yet trusted in the VOUCHED list. size:M 30-99 changed lines (additions + deletions). labels Nov 22, 2026
@coderabbitai

coderabbitai Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

GitLab merge request normalization now retains source project IDs when cross-repository records lack a source path. GitLabCli looks up those projects and attaches resolved paths before creating summaries. Head-branch probes now keep the first selector for each distinct source branch.

Changes: GitLab source project resolution

Layer / File(s) Summary
Track unresolved source projects
packages/source-control-gitlab/src/server/gitLabMergeRequests.ts
Normalization records the source project ID for cross-repository merge requests that lack a source path. withSourceProjectPath removes the unresolved ID and applies the path and derived owner login when available.
Resolve source projects in merge request records
packages/source-control-gitlab/src/server/GitLabCli.ts, packages/source-control-gitlab/src/server/GitLabSourceControlProvider.git.test.ts
GitLabCli looks up unresolved project IDs through the GitLab API. Listing caches lookups when the source selector includes an owner; individual retrieval also resolves the source project path. Tests cover fork and upstream selector behavior, including failed lookups.

GitLab head branch selectors

Layer / File(s) Summary
Deduplicate selectors by source branch
packages/source-control-gitlab/src/server/GitLabSourceControlProvider.ts, packages/source-control-gitlab/src/server/GitLabSourceControlProvider.test.ts
headBranchProbe keeps the first selector for each distinct source branch, including owner-qualified selectors. Tests cover duplicate selectors in both input orders.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Suggested reviewers: juliusmarminge, saphid

Merge Risk: Minimal · up to c7c60

This change names the source project of GitLab fork merge requests so existing-MR matching can find them. No concrete defects were established in the reviewed changes, and the merge risk is low. A live GitLab instance was not tested.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "fix(gitlab): find merge requests opened from a fork" matches the main change. The PR makes GitLab fork merge requests resolve their head repository name and owner, so Git status and the cre…
Description check Passed The description follows the template. It has Problem, Change, Scope, and Verification sections, and each section gives specific content. The Problem section gives reproduction steps and the root cause…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "fix(gitlab): find merge requests opened from a fork" matches the main change. The PR makes GitLab fork merge requests resolve their head repository name and owner, so Git status and the create-MR check can find them. The title is short, uses a conventional commit prefix, and names the affected provider and the bug.

Full details: Description check

Explanation

The description follows the template. It has Problem, Change, Scope, and Verification sections, and each section gives specific content. The Problem section gives reproduction steps and the root cause. The Change section lists the lookup, caching, failure handling, and the cases that skip extra calls. The Scope section explains why no issue was opened and links related PRs. The Verification section lists a named regression test, the observed failure before the fix, the pass after the fix, and the test counts. It also states what was not checked, a live GitLab instance. The description does not link a tracked issue, but it explains why none was needed, as the template allows for small obvious fixes.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between ab8e4cb and c7c6074.

Files selected for processing: 4

  • packages/source-control-gitlab/src/server/GitLabCli.ts
  • packages/source-control-gitlab/src/server/GitLabSourceControlProvider.git.test.ts
  • packages/source-control-gitlab/src/server/GitLabSourceControlProvider.test.ts
  • packages/source-control-gitlab/src/server/GitLabSourceControlProvider.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 3 remain after this review.

@juliusmarminge juliusmarminge added the takeover:in-progress A takeover lead is working on this PR label Nov 22, 2026
juliusmarminge and others added 3 commits November 22, 2026 14:43
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Listing a branch's merge requests from the upstream itself looked up every
fork's source project, one glab call each, though none of them can match.
GitLab's head probe now keeps the owner-qualified selector GitManager sends
first for a fork head, and only that list resolves source project ids, once
per distinct id and concurrently.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@juliusmarminge

Copy link
Copy Markdown
Member

Evidence

Created a real GitLab fork MR from feature/x into upstream main. Opened the same branch in fresh web app state on both commits and invoked create_pr. Base missed the MR; head displayed it and returned opened_existing. Chromium, 1280×800, light theme, replay-agent history.

Before After
2f19cec079 c7c6074bb2
Before: Create MR despite existing fork MR After: existing fork MR title and number displayed
Before recording After recording

Scenario driver

Limitation: base's Create MR action stopped at disabled text generation, so the original duplicate-MR error was not captured. Discovery failure and head's reuse result were verified.

Not shown:

  • The original GitLab duplicate-MR rejection: base's Create MR action stopped earlier because the scenario disables real text-generation providers. Head's same create_pr RPC returned opened_existing without requiring text generation.

@juliusmarminge juliusmarminge added takeover:ready Takeover done; auto-lands when gates pass and removed takeover:in-progress A takeover lead is working on this PR labels Nov 22, 2026
@juliusmarminge
juliusmarminge merged commit 2251de4 into pingdotgg:main Nov 22, 2026
55 checks passed
@juliusmarminge juliusmarminge removed the takeover:ready Takeover done; auto-lands when gates pass label Nov 22, 2026
gianpaj pushed a commit to gianpaj/t3code that referenced this pull request Nov 22, 2026
Co-authored-by: Abhiram-745 <237478249+Abhiram-745@users.noreply.github.com>
Co-authored-by: Julius Marminge <julius0216@outlook.com>
github-actions Bot added a commit to omarcresp/t3code-flake that referenced this pull request Nov 22, 2026
**v0.1.12-nightly.20261122.5111** · 30 changes from 10 contributors

- **Multi-file diffs.** Open diff now shows every file in a multi-file Codex patch.
- **Mixed-content paste.** Pasting a message with text and a picture now keeps both.
- **Queued attachments.** Edit a queued message without losing its image or file attachment chips.
- **Pull request checks.** Agents watching a pull request can recognize checks that already passed instead of waiting indefinitely.
- **Notebook outputs.** Saved HTML outputs now appear when you scroll them into view.

### Plus 24 more bug fixes and performance improvements.

<details>
<summary>Full changelog</summary>

## What's Changed
* perf(mobile): keep image bytes outside draft JSON by @t3dotgg in pingdotgg/t3code#9727
* fix(server): watch_pull_request says when checks already passed by @juliusmarminge in pingdotgg/t3code#40866
* fix(codex): Open diff shows every file of a multi-file patch by @Abhiram-745 in pingdotgg/t3code#40874
* fix(server): ACP startup gives up when the agent never answers the handshake by @juliusmarminge in pingdotgg/t3code#40864
* fix(server): a branch prefixed with another remote's name publishes under its full name by @Abhiram-745 in pingdotgg/t3code#40877
* fix(server): list open delegated tasks when task_status or task_cancel finds no match by @Project516 in pingdotgg/t3code#40886
* fix(gitlab): find merge requests opened from a fork by @Abhiram-745 in pingdotgg/t3code#40894
* fix(web): pasting a chat message with text and a picture keeps both by @juliusmarminge in pingdotgg/t3code#40909
* fix(antigravity): bound silent post-settle background command holds by @Lokkuchakreshkumar in pingdotgg/t3code#40858
* fix(desktop): WSL is not offered or started when only the Windows install stub exists by @juliusmarminge in pingdotgg/t3code#40918
* fix(server): idle /ws connections behind a reverse proxy no longer drop every 60s by @juliusmarminge in pingdotgg/t3code#40932
* fix(server): thread reads no longer attribute T3 Code's compact-before-send /compact to the user by @juliusmarminge in pingdotgg/t3code#40934
* fix(web,mobile): @-file mentions show by name in message previews, not as raw links by @tiliakoos in pingdotgg/t3code#40924
* fix(web): tool calls stay grouped after a usage-limit pause again by @matthew-waters in pingdotgg/t3code#40905
* fix(server): t3 doctor no longer reports a database just under 1 GiB as "1024.0 MiB" by @tiliakoos in pingdotgg/t3code#40952
* fix(web): show clone failure after progress is dismissed by @StiensWout in pingdotgg/t3code#40951
* Invalidate pending theme imports when a replacement is too large by @StiensWout in pingdotgg/t3code#40965
* fix(mobile): show linked thread history page errors by @StiensWout in pingdotgg/t3code#40973
* fix(client-runtime): skip waiting for lower-priority linked addresses by @StiensWout in pingdotgg/t3code#40989
* fix(web): navigate Excel sheets from the focused tab by @StiensWout in pingdotgg/t3code#41008
* fix(mobile): bound app-owned composer attachment filenames by @StiensWout in pingdotgg/t3code#40991
* fix(web): prioritize visible saved notebook outputs by @StiensWout in pingdotgg/t3code#40998
* fix(web): editing a queued message keeps its attachment chips resolved by @smirea in pingdotgg/t3code#40945
* fix(server): unlinking an environment ends its session on the other machine by @juliusmarminge in pingdotgg/t3code#41005
* fix(mobile): scope Git result banners to their originating thread by @StiensWout in pingdotgg/t3code#41015
* fix(web): keep the conversation when a pairing tab closes by @StiensWout in pingdotgg/t3code#41025
* fix: restart linked thread reads when trying again by @StiensWout in pingdotgg/t3code#41020
* fix(client-runtime): count ambiguous projects in chat file links by @StiensWout in pingdotgg/t3code#40986
* fix(mobile): keep media actions on each sent image page by @StiensWout in pingdotgg/t3code#41018
* perf(server): a run's provider turn lookup is linear, not quadratic by @navidnadali in pingdotgg/t3code#38791

## New Contributors
* @Lokkuchakreshkumar made their first contribution in pingdotgg/t3code#40858
* @matthew-waters made their first contribution in pingdotgg/t3code#40905

**Full Changelog**: pingdotgg/t3code@v0.1.12-nightly.20261122.5098...v0.1.12-nightly.20261122.5111

</details>


Upstream release: https://github.com/pingdotgg/t3code/releases/tag/v0.1.12-nightly.20261122.5111
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M 30-99 changed lines (additions + deletions). vouch:unvouched Author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants